package core.network.client2game.handler.union;

import business.global.club.ClubMember;
import business.global.club.ClubMgr;
import business.global.union.Union;
import business.global.union.UnionMgr;
import business.player.Player;
import business.player.PlayerMgr;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.exception.WSException;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;
import core.network.http.proto.SData_Result;
import jsproto.c2s.iclass.union.CUnion_BanCfgZhongZhi;
import jsproto.c2s.iclass.union.CUnion_GroupingPid;
import jsproto.c2s.iclass.union.SUnion_GroupingInfo;

import java.io.IOException;
import java.util.Objects;

/**
 * 赛事受限权限
 * @author zaf
 *
 */
public class CUnionBanCfgAdd extends PlayerHandler {

	@Override
	public void handle(Player player, WebSocketRequest request, String message)
			throws WSException, IOException {
		final CUnion_BanCfgZhongZhi req = new Gson().fromJson(message, CUnion_BanCfgZhongZhi.class);
		// 获取指定的赛事信息
		Union union= UnionMgr.getInstance().getUnionListMgr().findUnion(req.getUnionId());
		if (Objects.isNull(union)) {
			request.error(ErrorCode.UNION_NOT_EXIST,"CUnionGroupingPidAdd null == club ClubID:{%d},UnionId:{%d}",req.getClubId(),req.getUnionId());
			return;
		}
		ClubMember clubMember = ClubMgr.getInstance().getClubMemberMgr().find(player.getPid(),req.getClubId());
		if(Objects.isNull(clubMember)){
			request.error(ErrorCode.CLUB_NOTCLUBMEMBER, "CLUB_NOTCLUBMEMBER");
			return;
		}
		if(clubMember.isNotClubCreate()){
			request.error(ErrorCode.CLUB_NOT_CREATE, "CLUB_NOT_CREATE");
			return;
		}
		SData_Result result = union.addUnionBanConfigPid(req,req.getPid());
		if(ErrorCode.Success.equals(result.getCode())) {
			request.response(result.getData());
		} else {
			request.error(result.getCode(), result.getMsg());
		}

	}
}
